package server.content;

import server.content.skills.misc.SkillConstants;
import server.event.CycleEvent;
import server.event.CycleEventContainer;
import server.event.CycleEventHandler;
import server.event.Event;
import server.event.EventContainer;
import server.event.EventManager;
import server.game.players.Client;
import server.game.players.Player;

/**
 * 
 * @author Bailey
 * 
 */
public class LadderManager {

	public static LadderOptions ladderStage = null;

	public static void climb(final Player player,
			final LadderOptions ladderStage) {
		if (ladderStage == null)
			return;
		if (getLadderStage() == (ladderStage))
			return;
		setLadderStage(ladderStage);
		final Client c = (Client) player;
		c.startAnimation(
				ladderStage.equals(LadderOptions.GOING_UP) ? 828 : 827, 0);
		c.getPA().requestUpdates();
		c.getPA()
				.movePlayer(
						c.getX(),
						c.getY(),
						ladderStage.equals(LadderOptions.GOING_UP) ? c
								.getHeightLevel() + 1 : 0);
		setLadderStage(null);

	}

	public static void ladders(Player player, int objectId) {
		final Client c = (Client) player;
		switch (objectId) {

		case 1738:
			c.turnPlayerTo(c.objectX, c.objectY);
			c.startAnimation(828);
			c.getPA().requestUpdates();
			EventManager.getSingleton().addEvent(new Event() {

				@Override
				public void execute(EventContainer container) {
					c.getPA().movePlayer(c.getX(), c.getY(), 1);
					container.stop();
				}
			}, 3);
			break;
		case 1740:
			c.turnPlayerTo(c.objectX, c.objectY);
			c.startAnimation(827);
			c.getPA().requestUpdates();
			EventManager.getSingleton().addEvent(new Event() {

				@Override
				public void execute(EventContainer container) {
					c.getPA().movePlayer(c.getX(), c.getY(), c.heightLevel - 1);
					container.stop();
				}
			}, 3);
			break;
		case 1739:
			c.getDH().sendDialogues(2015, -1);
			break;

		case 1747:
		case 2641:
			// case 1738:
		case 1750:
			climb(player, LadderOptions.GOING_UP);
			break;

		case 2113:
			final Client c2 = (Client) player;
			if (c2.mine.getPlayerLevel() >= 60) {
				c2.startAnimation(827, 0);
				c2.getPA().requestUpdates();
				c2.getPA().movePlayer(3021, 9739, 0);
				c2.sendMessage("You climb down the ladder...");
			} else {
				c2.sendMessage("You need 60 mining to enter.");
			}
			break;

		// case 1739:
		// final Client c = (Client) player;
		// c.getDH().sendDialogues(2015, -1);
		// break;

		case 1749:
		case 1746:
		//case 1740:
			climb(player, LadderOptions.GOING_DOWN);
			break;

		case 1755:
			final Client c3 = (Client) player;
			c3.startAnimation(827, 0);
			c3.getPA().requestUpdates();
			c3.getPA().movePlayer(3238, 3457, 0);
			c3.sendMessage("You climb up the ladder...");
			break;

		}
	}

	public static void setLadderStage(LadderOptions ladderStage) {
		LadderManager.ladderStage = ladderStage;
	}

	public static LadderOptions getLadderStage() {
		return ladderStage;
	}

	public enum LadderOptions {
		GOING_UP, GOING_DOWN
	}

}